//
//  YLFundListCollectionViewCell.m
//  YLFinanceService
//
//  Created by she1323 on 2017/11/27.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLFundListCollectionViewCell.h"
#import "YLFuncListModel.h"
#import "YLGlobeHeader.h"
@interface YLFundListCollectionViewCell()



/**
 基金类型文字
 */
@property (weak, nonatomic) IBOutlet UILabel *productTypeTextLabel;

/**
 名称
 */
@property (weak, nonatomic) IBOutlet UILabel *productNameLabel;

/**
 规模
 */
@property (weak, nonatomic) IBOutlet UILabel *productSizeLabel;

/**
 期限
 */
@property (weak, nonatomic) IBOutlet UILabel *durationLabel;

/**
 募集状态
 */
@property (weak, nonatomic) IBOutlet UILabel *establishmentStatueTextLabel;

@end


@implementation YLFundListCollectionViewCell


- (void)setModel:(YLFuncListModel *)model
{
    _model = model;
    _productNameLabel.text = model.productName;
    
    if (model.productName.length > 17) {
        _productNameLabel.text = [NSString stringWithFormat:@"%@...", [model.productName substringToIndex:16]];
    }
    
    NSString *productSizeStr = [NSString stringWithFormat:@"%.0f", _model.productSize / 10000];
    _productSizeLabel.attributedText = [self str:productSizeStr strFont:[UIFont systemFontOfSize:28.0f] andAppendString:@"(万)" appendStrFont:[UIFont systemFontOfSize:18.0f]];
    
    NSString *durationStr = model.duration;
    if ([model.extendedPeriodMonth integerValue] != 0) {
       durationStr = [NSString stringWithFormat:@"%@+%@", model.duration, model.extendedPeriodMonth];
    }
    
    
    _durationLabel.attributedText =  [self str:durationStr strFont:[UIFont systemFontOfSize:18.0f] andAppendString:@"(月)" appendStrFont:[UIFont systemFontOfSize:18.0f]];
    
    
    _productTypeTextLabel.textColor = YLColor(214, 198, 170);
    _establishmentStatueTextLabel.text = model.establishmentStatueText;
    
    // 募集结束
    if (model.establishmentStatue == 1) {
        _durationLabel.textColor = _establishmentStatueTextLabel.textColor = _productSizeLabel.textColor = _productNameLabel.textColor = [UIColor lightGrayColor];
    } else {
        _productNameLabel.textColor =  _durationLabel.textColor = YLColor(30, 30, 30);
        _establishmentStatueTextLabel.textColor = _productSizeLabel.textColor = YLMainColor;

    }
    

    NSString *productType = [NSString stringWithFormat:@"  %@  ", model.productTypeText];
 
    _productTypeTextLabel.text = productType;
    _productTypeTextLabel.layer.borderColor = _productTypeTextLabel.textColor.CGColor;
    
}

#pragma mark 根据2段文字生成富文本
- (NSAttributedString *)str:(NSString *)string strFont:(UIFont *)strFont andAppendString:(NSString *)appendString appendStrFont:(UIFont *)appendStrFont
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName : strFont}];
    [str appendAttributedString:[[NSMutableAttributedString alloc] initWithString:appendString attributes:@{NSFontAttributeName: appendStrFont}]];
    return str;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    _productTypeTextLabel.layer.borderWidth = 1.0f;
    _productTypeTextLabel.layer.masksToBounds = YES;
    _productTypeTextLabel.layer.cornerRadius = 4.0f;
    // Initialization code
}



+ (NSString *)cellID
{
    return @"YLFundListCollectionViewCell";
}

@end
